package com.tao.china.taobaoapi.request;

import java.io.IOException;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.ItemsSearchRequest;
import com.taobao.api.response.ItemsSearchResponse;

/**
 * @author liuchao
 */
public class ItemsSearch {
    static TaobaoClient client=new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "12120462", "c5eed5e31351041ea23bfbb7744f8324");
    
    public static ItemsSearchResponse getSearchRes( Long cid,   Long   pageNo,Long pageSize ) throws ApiException{
        ItemsSearchRequest req=new ItemsSearchRequest();
        req.setFields("num_iid,title,nick,pic_url,cid,price,type,delist_time,post_fee,score,volume");
        req.setCid(cid);
        req.setPageNo(pageNo);
        req.setPageSize(pageSize);
        return client.execute(req);
    }
    
    public static Long getTotalResult (    Long cid    ) throws ApiException{
        ItemsSearchRequest req=new ItemsSearchRequest();
        req.setCid(cid);
        req.setFields("total_results");
        return client.execute(req).getTotalResults();
    }
    
    public static void main(String args[]) throws ApiException, IOException, InterruptedException
    {
        
        ItemsSearchResponse res = getSearchRes(14L,1L,200L);
        
    }
}
